<?php require("sessionStart.php");




/*---Function Begins---*/

//Determines if anything has been entered within Username and password. It does so by
//determining if anything is present in the associative array that by default contains
//the contents of $_GET or $_POST. It also checks if the associative array has the key
//'Username' which is the name value of the text box marked further below
if ( (sizeof ($_REQUEST) > 0) && isset($_REQUEST['Username']))
{

      //Strips whitespace from beginning and end of entered username and assigns that value to
      //the variable $username.
	$username = trim($_REQUEST['Username']);
      //Sets the value of entered password to the variable $pass
	$pass = $_REQUEST['Password'];

	$cmdEncrypt = '../admin/users/encrypt.pl ' .EscapeShellArg($pass);
	$retrunCmdEncrypt = exec($cmdEncrypt,$cmdEncryptOutput,$cmdEncryptResult);

         //Checks to see if both username and password are entered with no value.
           if (( $_REQUEST["Username"] != "")  && ($_REQUEST["Password"] != "") )
           {


				/*********************************************************************/

				/**********   calling the Perl script        *************************/

				/*********************************************************************/

				$cmd = './auth.pl ' .EscapeShellArg($username).' '.EscapeShellArg($cmdEncryptOutput[0]);
				$returnValue = exec($cmd,$output,$result);

				//if user is authenticated
				if ($result == 9)
				{


						//Remove whitespace and make $username the current sessions
						//username ($_SESSION['Username'])
						$_SESSION['Username'] = trim($username);


					  //Remove whitespace and make $permission the current sessions
					  //permission level ($_SESSION['group'])
						$_SESSION['group'] = trim($output[1]);

				}

				/*********************************************************************/
				/*********************************************************************/
				/*********************************************************************/
				/*********************************************************************/

	       }
}
/*---Function End---*/
header( 'Location:' . $_SERVER["HTTP_REFERER"]  ) ;
?>
